define(function(require, exports, module){
	//加载资源
	require("resource/js/easyui/themes/icon.css");
	require("resource/js/easyui/easyloader.js");
	require("resource/js/component/rules.js");
	var easyutil = require("resource/js/component/easyutil.js");
	var easycombobox = require("resource/js/component/easycombobox.js");
    //查询出所有下拉菜单的选项
	var suc_config = function(){
		return {
			type:"imphouse",
			name:'路桩配置数据列表',
			column:[[
			        {field:'serid',title:'批次',width:100,align:'center',height:50},
			        {field:'seqnum',title:'行号',width:30,align:'center',height:50},
			        {field:'col0',title:'桩号',width:80,align:'center',height:50},
			        {field:'col1',title:'纬度',width:120,align:'center',height:50},
			        {field:'col2',title:'经度',width:50,align:'center',height:50},
			        /*{field:'col3',title:'民族',width:50,align:'center',height:50},
			        {field:'col4',title:'出生日期',width:60,align:'center',height:50},
			        {field:'col5',title:'学历',width:80,align:'center',height:50},
			        {field:'col6',title:'人员类别',width:80,align:'center',height:50},
			        {field:'col7',title:'所在党支部',width:100,align:'center',height:50},
			        {field:'col8',title:'加入党组织日期',width:80,align:'center',height:50,hidden:true},
			        {field:'col9',title:'转为正式党员日期',width:100,align:'center',height:50,hidden:true},
			        {field:'col10',title:'工作岗位',width:100,align:'center',height:50,hidden:true},
			        {field:'col11',title:'家庭住址(具体到门牌号)',width:100,align:'center',height:50,hidden:true},
			        {field:'col12',title:'联系电话(手机号)',width:100,align:'center',height:50},
			        {field:'col13',title:'是否为失联党员',width:100,align:'center',height:50,hidden:true},
			        {field:'col14',title:'失去联系日期',width:100,align:'center',height:50,hidden:true},
			        {field:'col15',title:'是否为流动党员',width:100,align:'center',height:50,hidden:true},
			        {field:'col16',title:'外出流向',width:100,align:'center',height:50,hidden:true},
			        {field:'col17',title:'R',width:100,align:'center',height:50},
			        {field:'col18',title:'S',width:100,align:'center',height:50},
			        {field:'col19',title:'T',width:100,align:'center',height:50},
			        {field:'col20',title:'U',width:100,align:'center',height:50},
			        {field:'col21',title:'V',width:100,align:'center',height:50},
			        {field:'col22',title:'W',width:100,align:'center',height:50},
			        {field:'col23',title:'X',width:100,align:'center',height:50},
			        {field:'col24',title:'Y',width:100,align:'center',height:50},
			        {field:'col25',title:'Z',width:100,align:'center',height:50}*/
			        ]]
		};
	}
	
	var err_config = {
		type:"validateError",
		name:'路桩导入数据校验错误列表',
		column:[[
	         {field:'id',title:'主键',width:100,align:'center',height:50,hidden:true},
	         {field:'excelcol',title:'列',width:100,align:'center',height:50},
	         {field:'excelrow',title:'行',width:100,align:'center',height:50},
	         {field:'error',title:'错误信息',width:100,align:'center',height:50},
	         {field:'batch_id',title:'批次号',width:100,align:'center',height:50},
	         {field:'error_type',title:'提示类型',width:100,align:'center',height:50,formatter:function(value,row,index){
	        	 if(value=='warn'){
	        		return "<sapn style='color:#af8036'>'"+'警告'+"'</span>";
	        	 }else{
	        		return "<sapn style='color:#ff0000'>'"+'错误'+"'</span>";
	        	 }
	         }}
	        
		]]
	};
	var dgutil = undefined;
	var datagridconfig = undefined;
	var flag = true;
	
	
	var valFunc = function(){
		$("#validateData").bind('click',function(){
			$("#validateData").unbind("click");
			$("#validateData").attr('class',"up-btn-dis");
			//去验证
			easyutil.ajaxHandler(BASEPATH+'/dcs/section/saveRoadValidate.htm',$("#searchformValidate").serializeJson(),function(code,msg,data){
				if(data.errorCount!=undefined && data.errorCount > 0){
					var buttons ={ 
							title:{
								_class:"",
								text:'错误数据列表'
							}};
		        	datagridconfig.toolbar = buttons;
	        		datagridconfig.columns = suc_config().column;
	        		datagridconfig.fitColumns = true;
	    	    	datagridconfig.url = BASEPATH+'/dcs/section/queryImpRoadErrorByPage.htm';
	    	    	datagridconfig.onLoadSuccess = function(data){
	    	    		$.each(data.rows,function(i,v){
	    	    			if(v.error_type=='error'){
	    	    				$("#marksure").unbind("click");
				        		$("#marksure").attr('class',"up-btn-dis");
				        		flag = false;
	    	    			}
	    	    		});
	    	    		if(flag){
	    	    			$("#validatetrue").show();
	    	    			$("#validatediv").hide();
	    	    		}
	    	    	};
	    	    	dgutil = new easyutil.ajaxDataGrid(datagridconfig);
	    	    	dgutil.pager();
				}else{
					$.messager.confirm('系统提示','数据验证成功，是否导入？',function(r){
						if(r){
							$("#marksure").click();
						} else {
							$("#validatetrue").show();
							$("#validatediv").hide();
						}
					});
					
				}
			});
		});
		$(".backbtn").click(function(){
			easyutil.ajaxHandler(BASEPATH+"/dcs/section/deleteImpData.htm",{"batchId":$("#batchId").val()},function(){
				location.reload();
			});
			
		});
		$("#marksure").bind('click',function(){
			$("#marksure").unbind("click");
			$("#marksure").attr('class',"up-btn-dis");
			easyutil.ajaxHandler(BASEPATH+'/dcs/section/saveImpRoad.htm',$("#searchformValidate").serializeJson(),function(code,msg,data){
	            if(data.flag && data.flag == '0'){
	            	$.messager.show({title:'系统提示',msg:'数据导入成功',timeout:5000,showType:'slide'});
	            	$("#validateDialog").dialog('close');
	            } else {
	            	$.messager.show({title:'系统提示',msg:'数据导入失败，请重新导入',timeout:5000,showType:'slide'});
	            	$("#validateDialog").dialog('close');
	            }
			});
		});
	}
		
	
	function initPage(){
		dgutil = new easyutil.ajaxDataGrid(datagridconfig);
		valFunc();
	}
	
	module.exports = {
		trans:function(id){
			$("#batchId").val(id.batchId);
			$("#sectionId").val(id.sectionId);
			var buttons ={ 
				title:{
					_class:"",
					text:'导入数据展示列表'
				},
				btn:[
			]};
			datagridconfig = {
					fitColumns:true,
					singleSelect:true,
					striped:true,
					autoRowHeight:false,
					fit: true,
					url:BASEPATH+'/dcs/section/queryRoadFromImportByPage.htm',
					toolbar:buttons,
					columns:suc_config().column,
					eid:"dgval",
					args:"searchformValidate"
					
			};
			using(["datagrid","parser","messager","dialog","combobox"],function(){
				initPage();
			});
		}
	}
});


